package com.bos.data.repositories.impl;

import com.bos.data.repositories.SalesRepository;
import com.bos.common.PageData;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Repository
@Transactional
public class SalesRepositoryImpl extends BaseRepository implements SalesRepository {
    public PageData findSales(List<String> leaderList, List<String> statusList, int pageSize, int pageIndex) {
        StringBuffer sb = new StringBuffer();
        sb.append(" select * from  sales where 1=1 ");
        Map map = new HashMap();
        if (leaderList != null && leaderList.size() != 0) {
            String permit = "";
            for (int a = 0; a < leaderList.size(); a++) {
                if (a == 0) {
                    permit = permit + "'" + leaderList.get(a) + "'";
                } else {
                    permit = permit + ", " + "'" + leaderList.get(a) + "'";
                }
            }
            permit = "(" + permit + ")";
            sb.append(" and sleader in " + permit);
        }
        if (statusList != null && statusList.size() != 0) {
            String permit = "";
            for (int a = 0; a < statusList.size(); a++) {
                if (a == 0) {
                    permit = permit + "'" + statusList.get(a) + "'";
                } else {
                    permit = permit + ", " + "'" + statusList.get(a) + "'";
                }
            }
            permit = "(" + permit + ")";
            sb.append(" and status in " + permit);
        }
        List order=new ArrayList();
        order.add("status");
        return this.getPage(sb.toString(), map, pageSize, pageIndex,order,false);
    }
}
